<template>
   <image :src="bannerPicture" class="top_img"/>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import {getHotList} from "@/api/hot/index"
import type {hotPageItem, hotTagList, tag, hotQuery} from "@/types/hot"
let params = ref<hotPageItem>({
  subType: '1', 
  pageSize: 10, 
  page: 1
})
let bannerPicture = ref('')
let tagList = ref<tag[]>([])

const urlMap = [
   {type: 1, title: '特惠推荐', url: '/hot/preference'},
   {type: 2, title: '爆款推荐', url: '/hot/inVogue'},
   {type: 3, title: '一站买全', url: '/hot/oneStop'},
   {type: 4, title: '新鲜好物', url: '/hot/new'},
]

// 路由参数可以通过onLoad获取，还能通过defindProps获取
// onLoad((parms ) => {
//   type.value = parms?.type || 1
// uni.setNavigationBarTitle({
//   title: urlMap[type.value - 1].title
// });
// })
let query = defineProps<{
  type: number
}>()

let typeObj = urlMap.find(v => v.type = query.type) as hotQuery

uni.setNavigationBarTitle({
  title: typeObj?.title || ''
});

onLoad(() => {
  getTagList()
})

// 获取数据
const getTagList = async () => {
  let res = await getHotList<hotTagList<tag>>(typeObj.url, params)

  bannerPicture.value = res.result?.bannerPicture 

  tagList.value = res.result.subTypes || []

} 
 
</script>

<style scoped lang='scss'>
.top_img {
  width: 100%;
  height: 230rpx;
}
</style>
